﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web.Mvc;

namespace CMS
{
    public class RouteManager
    {
        RouteCollection _routes;
        public RouteCollection Routes
        {
            get
            {
                return _routes;
            }
        }
        public RouteManager(RouteCollection routes)
        {
            _routes = routes;
        }
        public void RegisterRoutes()
        {
            _routes.Clear();
            SetRouteForAdmin();
            RegisterRoutesForPortal();
            Route r = new Route("Default", new CmsRouteHandler());
            r.DataTokens = new RouteValueDictionary(new { area = "Portal", Namespaces = new string[] { "Winter.Sites.Portal.Controllers.*", "Winter.Portal.Admin.*" } });
            r.Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional });
            r.Url = "";
            _routes.Add(r);
            //get pages in database and set route for them
            //set routes for all locate, controller

        }
        private void RegisterRoutesForPortal()
        {
            Route r = new Route("Portal", new CmsRouteHandler());
            r.DataTokens = new RouteValueDictionary(new { area = "Portal", Namespaces = new string[] { "Winter.Sites.Portal.Controllers.*", "Winter.Sites.Portal.*" } });
            r.Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional });
            r.Url = "Portal/{controller}/{action}/{id}";
            _routes.Add(r);
        }

        private void SetRouteForAdmin()
        {
            Route r = new Route("Admin", new CmsRouteHandler());
            r.DataTokens = new RouteValueDictionary(new { area = "Admin", Namespaces = new string[] { "Winter.Sites.Admin.Controllers.*", "Winter.Sites.Admin.*" } });
            r.Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional });
            r.Url = "Admin/{controller}/{action}/{id}";
            _routes.Add(r);
        }
    }
}
